//
//  CarTeamCell.m

//  Created 阿帕 on 2019/12/28.
//  Copyright © 2019 GCY. All rights reserved.
//

#import "CarTeamJoinedCell.h"

@interface CarTeamJoinedCell ()
@property (weak, nonatomic) IBOutlet UIImageView *selectedImageView;
@property (weak, nonatomic) IBOutlet UIImageView *avatarImageView;
@property (weak, nonatomic) IBOutlet UILabel *teamNameLabel;
@property (weak, nonatomic) IBOutlet UIView *lineView;
@property (weak, nonatomic) IBOutlet UILabel *teamDesLabel;
@property (weak, nonatomic) IBOutlet UILabel *xieYiStateLabel;
@property (weak, nonatomic) IBOutlet UIView *line1;

@end

@implementation CarTeamJoinedCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    _teamNameLabel.textColor = Dark_TextColor;
    _teamNameLabel.adjustsFontSizeToFitWidth = YES;
    _teamDesLabel.textColor = Light_TextColor;
    _xieYiStateLabel.textColor = Dark_TextColor;

    _line1.backgroundColor = BackgroundColor;
    _lineView.backgroundColor = BackgroundColor;
    [_teamTelButton setTitleColor:Dark_TextColor forState:UIControlStateNormal];
    [_teamTelButton setImage:image(@"gcy_icon_carteam_tel") forState:UIControlStateNormal];
    [_teamTelButton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
    [_exitCarTeamButton setBackgroundColor:Orange_Color];
    cut(_exitCarTeamButton, 3);
    
    UIView *btView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 126, ScreenW, 45)];
    btView.tag = 1000;
    [self.contentView addSubview:btView];
}

- (void)setModel:(CarTeamModel *)model {
    
    _model = model;

    _teamNameLabel.text = model.name;
    _teamDesLabel.text = model.linkMan;
    setNetImage(_avatarImageView, model.headImg, @"gcy_img_main_head");
    [_teamTelButton setTitle:model.phone forState:UIControlStateNormal];
    
    if (model.collection == 1){
        _xieYiStateLabel.text = @"代收协议状态：已同意";
        _xieYiStateLabel.textColor = Dark_TextColor;;
    }else {
        _xieYiStateLabel.text = @"代收协议状态：未授权或超出协议授权时间";
        _xieYiStateLabel.textColor = Red_TextColor;;
    }
    
    UIView *btView = [self viewWithTag:1000];
    if (btView) {
        //解决按钮重用问题
        [btView removeAllSubviews];
    }
    
    NSMutableArray *tabArray = [[NSMutableArray alloc] init];
    NSMutableArray *iconArray = [[NSMutableArray alloc] init];
    
    [tabArray addObject:@"添加代收协议"];
    [iconArray addObject:@"gcy_icon_yundan_edit"];
    [tabArray addObject:@"协议记录"];
    [iconArray addObject:@"gcy_icon_my_daishouxieyi"];
    
    if (Alone_Driver) {
        //独立司机添加退出车队
        [tabArray addObject:@"退出车队"];
        [iconArray addObject:@"gcy_icon_ydzx_cancel"];
    }
    
    //根据按钮的多少计算btn宽度
    CGFloat btnWidth = ScreenW/3;
    
    for (int i=0; i<tabArray.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = 100 + i;
        [button setBackgroundColor:[UIColor whiteColor]];
        [button setTitle:tabArray[i] forState:UIControlStateNormal];
        button.titleLabel.font = font(14);
        [button setTitleColor:Light_TextColor forState:UIControlStateNormal];
        [button setImage:image(iconArray[i]) forState:UIControlStateNormal];
        button.frame = CGRectMake(btnWidth * i, 0, btnWidth, 45);
        button.titleLabel.adjustsFontSizeToFitWidth = YES;
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [btView addSubview:button];
        [button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3];
    }
    
}

- (void)buttonClick:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(buttonIndexClick:withButton:)]) {
        [self .delegate buttonIndexClick:button.tag withButton:button];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
